<?php
namespace App\Model;

class Order extends \Eloquent{

    /**
     * The database used by the model.
     *
     * @var string
     */
    protected $table = 'order';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $guarded = [''];
    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = ['updated_at','deleted_at'];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [];

    public function __construct(array $attributes = []){
        parent::__construct($attributes);
    }

    public function products(){
        return $this->hasMany(Products::class,'order_id');
    }


    /**
     *
     *
     * @return void
     */
    public function generateOrderNo(){
       return  date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
    }


    /**
     * getOrderByNo
     *
     * @param mixed $orderno
     *
     * @return void
     */
    public static function getOrderByNo($orderno){
        return $this->where('orderno',$orderno)->first();
    }
}
